﻿

using System;
using System.Reflection;

public class ShapeFactory {
    //static String[] shapes = { "Rectangle", "Square", "Triangle" };
    /// <param name="id">三种shape的编号，0长方形，1正方形，2三角形</param>
    /// a, b, c为边长
    public static Shape? CreatShape(EShape shape, int a, int b = 0, int c = 0) {
        Console.Write($"{shape}\t ");
        switch (shape) {
            case EShape.Rectangle:
                Console.Write($"width = {a} length = {b}\n");
                return new Rectangle(a, b);
            case EShape.Square:
                Console.Write($"\t width = {a}\n");
                return new Square(a);
            case EShape.Triangle:
                Console.Write($"three sides : a = {a} b = {b} c = {c}\n");
                return new Triangle(a, b, c);
            default:
                return null;
        }
    }

    /// <param name="num">随机个数</param>
    /// <param name="sideRange">边长范围</param>
    public static Shape[] CreateRandomShapes(int num, int sideRange) {
        Random random = new();
        Shape[] shapes = new Shape[num];
        for (int i = 0; i < num; i++) {
            int a = random.Next(sideRange);
            int b = random.Next(sideRange);
            int c = random.Next(sideRange);
            int shapeId = random.Next(3);
            EShape shape = (EShape)shapeId;
            shapes[i] = CreatShape(shape, a, b, c);
        }
        return shapes;
    }

}